YZYZ.Admin.Route.newRouteWin 	= null;
YZYZ.Admin.Route.northPanel 	= null;
YZYZ.Admin.Route.newData 		= [[0,0],[1,1],[2,2],[3,3],[4,4],[5,5],[6,6],[7,7],[8,8],[9,9]];
YZYZ.Admin.Route.newDataSotre = new Ext.data.SimpleStore(
  {  
	  fields:['id','name'],  
	  data  :YZYZ.Admin.Route.newData 
  }
);
YZYZ.Admin.Route.newRecord = Ext.data.Record.create([
	{ name: 'id', type: 'string'},
	{ name: 'name', type: 'string'},
	{ name: 'contents', type: 'string'},
	{ name: 'price', type: 'string'},
	{ name: 'level', type: 'int'},
	{ name: 'routeGroupId',type:'int'}
]);
YZYZ.Admin.Route.newCombox = new Ext.form.ComboBox({  
         id: 'cxNewLevel', 
         allowBlank: false,  
         fieldLabel: '优先级',  
         hiddenName: 'hidLevel',  
         displayField: 'name',  
         valueField: 'id',  
         typeAhead: true,  
         triggerAction: 'all',  
         store: YZYZ.Admin.Route.newDataSotre,  
         mode: 'local',
         width:300 ,
         editable:false
 });
YZYZ.Admin.Route.saveNewRoute = function(){
	var contents 	= Ext.getCmp('routeContents').getValue();
	var price 		= Ext.getCmp('price').getValue();
	var name 		= Ext.getCmp('name').getValue();
	var level 		= Ext.getCmp('cxNewLevel').getValue();
	var routeGroupId= Ext.getCmp('addRouteGroup').getValue();
	if(Ext.isEmpty(name)) {
		YZYZ.Curtain.alert("名称不能为空");
		Ext.getCmp('name').markInvalid();
		return;
	}
	if(Ext.isEmpty(price)) {
		YZYZ.Curtain.alert("价格不能为空");
		Ext.getCmp('price').markInvalid();
		return;
	}
	if(isNaN(level) || level > 9) {
		YZYZ.Curtain.alert("优先级必须为0-9的数字");
		Ext.getCmp('cxNewLevel').markInvalid();
		return;
	}
	if(contents.length > 50000) {
		YZYZ.Curtain.alert("请将行程内容控制在50000个汉字以内");
		return;
	}
	if(Ext.isEmpty(routeGroupId)){
		YZYZ.Curtain.alert("行程板块不能为空");
		Ext.getCmp('addRouteGroup').markInvalid();
		return;
	}
	Ext.Ajax.request( {
		url		: Ext.get("addRouteUrl").dom.value,
		timeout	: 30000,
		method	: 'POST',
		params	: {
			name		: name,
			price 		: price,
			contents	: contents,
			level 		: level,
			routeGroupId: routeGroupId
		},
		success : function(result, request) {
			result = Ext.util.JSON.decode(result.responseText);
			if(result.code == YZYZ.success){
				YZYZ.Curtain.msg("添加成功");
				var rec = new YZYZ.Admin.Route.newRecord({
					name		: name,
					price 		: price,
					contents	: contents,
					level 		: level,
					routeGroupId: routeGroupId
				});
				rec.set("id", result.message);
				YZYZ.Admin.Route.grid.getStore().insert(0, rec);
				YZYZ.Admin.Route.newRouteWin.hide();
			}
			else {
				YZYZ.Curtain.alert(result.message);
				flag = false;
			}
		},
		failure : function(result, request) {
			YZYZ.Curtain.alert("程序出现错误或网络故障");
			flag = false;
		}
	});
	
};
YZYZ.Admin.Route.addNewRoute = function(){
	if(!YZYZ.Admin.Route.newRouteWin) {
		YZYZ.Admin.Route.northPanel = new Ext.form.FormPanel({
			labelWidth:150,
			labelAlign:'right',
			region:'north',
			height: 150,
			bodyStyle:'padding-top:20px',
			width:700,
			items:[{
				xtype:'textfield',
				width:300,
				id:'name',
				fieldLabel:'名称'
			},{
				xtype:'textfield',
				width:300,
				id:'price',
				fieldLabel:'价格'
			},
			YZYZ.Admin.Route.newCombox,
			YZYZ.Admin.Route.addGroupCB
			]
		});
		YZYZ.Admin.Route.centerPanel = new Ext.Panel({
		    title: '行程内容',
		    width: 700,
		    height: 300,
		    frame: true,
		    layout: 'fit',
		    region:'center',
		    
		    items: {
		        xtype: 'htmleditor',
		        id:'routeContents',
		        enableColors: true,
		        enableAlignments: true
		    }
		});
		YZYZ.Admin.Route.newRouteWin = new Ext.Window({
			width: 700,
			height: 500,
			layout:'border',
			title:'添加行程',
			modal:true,
			items:[YZYZ.Admin.Route.northPanel,YZYZ.Admin.Route.centerPanel],
			buttons:[{text:'保存',
			handler:YZYZ.Admin.Route.saveNewRoute},{
				text:'取消',
				handler:function(){
					YZYZ.Admin.Route.newRouteWin.hide();
				}
			}]
		});
	}else {
		Ext.getCmp("price").setValue("");
		Ext.getCmp("name").setValue("");
		Ext.getCmp("routeContents").setValue("");
	}
	YZYZ.Admin.Route.newRouteWin.show();
	
};